package com.y2w.gulimall.order.controller;

import com.y2w.gulimall.order.entity.OrderEntity;
import com.y2w.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate template;

    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "num",defaultValue = "10") Integer num){
        for(int i=0;i<num;i++){
            if(i%2==0) {
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId((long) i);
                entity.setCreateTime(new Date());
                entity.setName("哈哈" + i);
                template.convertAndSend("hello-java-exchange", "hello.java", entity,new CorrelationData(UUID.randomUUID().toString()));
            }else{
                OrderEntity entity=new OrderEntity();
                entity.setOrderSn(UUID.randomUUID().toString());
                template.convertAndSend("hello-java-exchange","hello.java",entity,new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "ok";
    }
}
